﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using ServerLibrary.Abstract;
namespace ServerLibrary.Concrete
{
     /// <summary>
    /// TODO: Implements configurator with server configurations.
    /// </summary>
    public class Configurator : IConfigurator
    {
        public string IpAddress
        {
            get;
            set;
        }
        
        public  uint Port
        {
            get;
            set;
        }

        public  ushort MaxUserQuantity
        {
            get;
            set;
        }
        
        public  List<string> availableFormats
        {
            get;
            set;
        }
        
        /// <summary>
        /// 
        /// </summary>
        public Configurator()
        {
            //Load("");
        }
        
        /// <summary>
        /// Loading configurations
        /// </summary>
        /// <param name="fileName">Path to config file</param>
        private  void Load(string fileName)
        {
            availableFormats = new List<string>();
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);
            XmlNode ConfigDate = doc.SelectSingleNode("ConfigDate");
            IpAddress = ConfigDate.SelectSingleNode("IpAddress").InnerText;
            Port = uint.Parse(ConfigDate.SelectSingleNode("Port").InnerText);
            MaxUserQuantity = ushort.Parse(ConfigDate.SelectSingleNode("MaxUserQuantity").InnerText);
            XmlNode AvailableFormats = ConfigDate.SelectSingleNode("AvailableFormats");
            foreach (XmlNode Format in AvailableFormats.ChildNodes)
            {
                availableFormats.Add(Format.InnerText);
            }

        }
    }
}
